package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.TAY;
import emulator.hardware.nmos6502.operands.NoOperand;

public class TAYTest {

	private Cpu6502 cpu;
	private TAY tay;

	@Before
	public void setUp() throws Exception {
		cpu = new Cpu6502();
		tay = new TAY();
	}

	@Test
	public void testTransferZero() throws EmulatorException {
		executeAndcheckTAY(0, Flags6502.FLAG_ZERO);
	}

	@Test
	public void testTransferPositive() throws EmulatorException {
		executeAndcheckTAY(5, 0);
	}

	@Test
	public void testTransferNegative() throws EmulatorException {
		executeAndcheckTAY(0x81, Flags6502.FLAG_NEGATIVE);
	}

	private void executeAndcheckTAY(int target, int expected_flags)	throws EmulatorException {
		cpu.setY(new HwByte(0xFF));
		cpu.setAccu(new HwByte(target));
		tay.execute(cpu, new NoOperand());
		assertEquals(target, cpu.getY().getNumber());
		assertEquals(target, cpu.getAccu().getNumber());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}
}
